//impacts of recession over parental income ventiles. And maybe ability, too.
import delimited "$dir/Model/simulated_data/simulated_data_base.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v


tab m if l == 1 & t == 18
tab m if l == 1 & t == 20 & e == 2
tab m if l == 1 & t == 22 & e == 3

//nix observations for kids who are in school
drop if t == 0 

//get lifetime wages and years worked for each individual simulation
preserve
collapse (sum) w l tax, by(i_v sim)
tempfile outcomes
ren w w_total
ren l l_total
ren tax tax_total
save `outcomes'
restore

merge m:1 i_v sim using `outcomes', keep(match) nogen

keep if t == 23 
gen enroll = (s>1)
gen hs = (e==1 & s==1)
gen drop = (e==1 & s>1)
gen sc = (e==2)
gen coll = (e==3)

su enroll hs drop sc coll w_total l_total tax_total

gen inc_dec = ceil(i_v / 2)


//weird stuff with d67
su tau I H if inc_dec == 1 | inc_dec == 2
tab s if inc_dec == 1 | inc_dec == 2
su tau if inc_dec == 1 | inc_dec == 2, d


su tau I H if inc_dec == 6 | inc_dec == 7
tab s if inc_dec == 6 | inc_dec == 7




//lifetime wages and years worked, average savings and educadtional attainment, by parent income ventile
collapse (mean) w_total l_total tax_total enroll hs drop sc coll gov_exp tau, by (inc_dec)
save "$temp/outcomes_base_pinc_dec", replace


//impacts of recession over parental income ventiles. And maybe ability, too.
import delimited "$dir/Model/simulated_data/simulated_data_rec.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v


tab m if l == 1 & t == 18
tab m if l == 1 & t == 20 & e == 2
tab m if l == 1 & t == 22 & e == 3


//nix observations for kids who are in school
drop if t == 0 

//get lifetime wages and years worked for each individual simulation
preserve
collapse (sum) w l tax, by(i_v sim)
tempfile outcomes
ren w w_total
ren l l_total
ren tax tax_total
save `outcomes'
restore

merge m:1 i_v sim using `outcomes', keep(match) nogen

keep if t == 23 
gen enroll = (s>1)
gen hs = (e==1 & s==1)
gen drop = (e==1 & s>1)
gen sc = (e==2)
gen coll = (e==3)

su enroll hs drop sc coll w_total l_total tax_total
gen inc_dec = ceil(i_v / 2)

//weird stuff with d67
su tau I H if inc_dec == 1 | inc_dec == 2
tab s if inc_dec == 1 | inc_dec == 2
su tau if inc_dec == 1 | inc_dec == 2, d

su tau I H if inc_dec == 6 | inc_dec == 7
tab s if inc_dec == 6 | inc_dec == 7



//lifetime wages and years worked, average savings and educadtional attainment, by parent income ventile
collapse (mean) w_total l_total tax_total enroll hs drop sc coll gov_exp tau, by (inc_dec)
ds inc_dec, not
foreach var in `r(varlist)'{
	ren `var' `var'_rec
}
save "$temp/outcomes_rec_pinc_dec", replace



//impacts of recession over parental income ventiles. And maybe ability, too.
import delimited "$dir/Model/simulated_data/simulated_data_rec_nopbr.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v


tab m if l == 1 & t == 18
tab m if l == 1 & t == 20 & e == 2
tab m if l == 1 & t == 22 & e == 3


//nix observations for kids who are in school
drop if t == 0 

//get lifetime wages and years worked for each individual simulation
preserve
collapse (sum) w l tax, by(i_v sim)
tempfile outcomes
ren w w_total
ren l l_total
ren tax tax_total
save `outcomes'
restore

merge m:1 i_v sim using `outcomes', keep(match) nogen

keep if t == 23 
gen enroll = (s>1)
gen hs = (e==1 & s==1)
gen drop = (e==1 & s>1)
gen sc = (e==2)
gen coll = (e==3)

su enroll hs drop sc coll w_total l_total tax_total
gen inc_dec = ceil(i_v / 2)

//weird stuff with d67
su tau I H if inc_dec == 1 | inc_dec == 2
tab s if inc_dec == 1 | inc_dec == 2
su tau if inc_dec == 1 | inc_dec == 2, d

//lifetime wages and years worked, average savings and educadtional attainment, by parent income ventile
collapse (mean) w_total l_total tax_total enroll hs drop sc coll gov_exp tau, by (inc_dec)
ds inc_dec, not
foreach var in `r(varlist)'{
	ren `var' `var'_rec_nopbr
}
save "$temp/outcomes_rec_pinc_dec_nopbr", replace


//get to work!
use "$temp/outcomes_base_pinc_dec", clear
merge 1:1 inc_dec using "$temp/outcomes_rec_pinc_dec", keep(match) nogen
merge 1:1 inc_dec using "$temp/outcomes_rec_pinc_dec_nopbr", keep(match) nogen

keep inc_dec tau*

ds tau*
foreach var in `r(varlist)'{
	replace `var' = `var' * 40000
	replace `var' = `var' / 1000
}

export delimited "$output/rec_tau_impacts.csv", replace 



